Skip to content

Commit 17388c5

Browse files
authored
[ru]: migrate JS interactive examples (#25860)
https://github.com/orgs/mdn/discussions/782
1 parent ca71b89 commit 17388c5

File tree

134 files changed

+1995
-134
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+1995
-134
lines changed

files/ru/web/javascript/guide/regular_expressions/character_classes/index.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,19 @@ slug: Web/JavaScript/Guide/Regular_expressions/Character_classes
77

88
Классы символов позволяют различать виды символов, к примеру, как различия между буквами и цифрами.
99

10-
{{EmbedInteractiveExample("pages/js/regexp-character-classes.html")}}
10+
{{InteractiveExample("JavaScript Demo: RegExp Character classes")}}
11+
12+
```js interactive-example
13+
const chessStory = "He played the King in a8 and she moved her Queen in c2.";
14+
const regexpCoordinates = /\w\d/g;
15+
console.log(chessStory.match(regexpCoordinates));
16+
// Expected output: Array [ 'a8', 'c2']
17+
18+
const moods = "happy 🙂, confused 😕, sad 😢";
19+
const regexpEmoticons = /[\u{1F600}-\u{1F64F}]/gu;
20+
console.log(moods.match(regexpEmoticons));
21+
// Expected output: Array ['🙂', '😕', '😢']
22+
```
1123

1224
## Типы
1325

files/ru/web/javascript/reference/functions/arguments/index.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,22 @@ slug: Web/JavaScript/Reference/Functions/arguments
1313
> [!NOTE]
1414
> "Подобный массиву" означает, что `arguments` имеет свойство {{jsxref("Functions/arguments/length", "length")}}, а элементы индексируются начиная с нуля. Но при этом он не может обращаться к встроенным методам {{JSxRef("Array")}}, таким как {{jsxref("Array.forEach", "forEach()")}} или {{jsxref("Array.map", "map()")}}. Подробнее об этом в [§Описании](#Описание).
1515
16-
{{EmbedInteractiveExample("pages/js/functions-arguments.html")}}
16+
{{InteractiveExample("JavaScript Demo: Functions Arguments")}}
17+
18+
```js interactive-example
19+
function func1(a, b, c) {
20+
console.log(arguments[0]);
21+
// Expected output: 1
22+
23+
console.log(arguments[1]);
24+
// Expected output: 2
25+
26+
console.log(arguments[2]);
27+
// Expected output: 3
28+
}
29+
30+
func1(1, 2, 3);
31+
```
1732

1833
## Синтаксис
1934

files/ru/web/javascript/reference/functions/default_parameters/index.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,19 @@ slug: Web/JavaScript/Reference/Functions/Default_parameters
77

88
**Параметры по умолчанию** позволяют задавать формальным параметрам функции значения по умолчанию в случае, если функция вызвана без аргументов, или если параметру явным образом передано значение `undefined`.
99

10-
{{EmbedInteractiveExample("pages/js/functions-default.html")}}
10+
{{InteractiveExample("JavaScript Demo: Functions Default")}}
11+
12+
```js interactive-example
13+
function multiply(a, b = 1) {
14+
return a * b;
15+
}
16+
17+
console.log(multiply(5, 2));
18+
// Expected output: 10
19+
20+
console.log(multiply(5));
21+
// Expected output: 5
22+
```
1123

1224
## Синтаксис
1325

files/ru/web/javascript/reference/functions/get/index.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,19 @@ slug: Web/JavaScript/Reference/Functions/get
77

88
Синтаксис **`get`** связывает свойство объекта с функцией, которая будет вызываться при обращении к этому свойству.
99

10-
{{EmbedInteractiveExample("pages/js/functions-getter.html")}}
10+
{{InteractiveExample("JavaScript Demo: Functions Getter")}}
11+
12+
```js interactive-example
13+
const obj = {
14+
log: ["a", "b", "c"],
15+
get latest() {
16+
return this.log[this.log.length - 1];
17+
},
18+
};
19+
20+
console.log(obj.latest);
21+
// Expected output: "c"
22+
```
1123

1224
## Синтаксис
1325

files/ru/web/javascript/reference/functions/rest_parameters/index.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,23 @@ slug: Web/JavaScript/Reference/Functions/rest_parameters
77

88
Синтаксис **остаточных параметров** функции позволяет представлять неограниченное множество аргументов в виде массива.
99

10-
{{EmbedInteractiveExample("pages/js/functions-restparameters.html")}}
10+
{{InteractiveExample("JavaScript Demo: Functions Rest Parameters")}}
11+
12+
```js interactive-example
13+
function sum(...theArgs) {
14+
let total = 0;
15+
for (const arg of theArgs) {
16+
total += arg;
17+
}
18+
return total;
19+
}
20+
21+
console.log(sum(1, 2, 3));
22+
// Expected output: 6
23+
24+
console.log(sum(1, 2, 3, 4));
25+
// Expected output: 10
26+
```
1127

1228
## Синтаксис
1329

files/ru/web/javascript/reference/global_objects/array/at/index.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,21 @@ slug: Web/JavaScript/Reference/Global_Objects/Array/at
77

88
Метод **`at()`** принимает значение в виде целого числа и возвращает элемент массива с данным индексом. В качестве аргумента метод принимает положительные и отрицательные числа. При отрицательном значении отсчёт происходит с конца массива.
99

10-
{{EmbedInteractiveExample("pages/js/array-at.html")}}
10+
{{InteractiveExample("JavaScript Demo: Array.at()")}}
11+
12+
```js interactive-example
13+
const array1 = [5, 12, 8, 130, 44];
14+
15+
let index = 2;
16+
17+
console.log(`An index of ${index} returns ${array1.at(index)}`);
18+
// Expected output: "An index of 2 returns 8"
19+
20+
index = -2;
21+
22+
console.log(`An index of ${index} returns ${array1.at(index)}`);
23+
// Expected output: "An index of -2 returns 130"
24+
```
1125

1226
## Синтаксис
1327

files/ru/web/javascript/reference/global_objects/array/concat/index.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@ slug: Web/JavaScript/Reference/Global_Objects/Array/concat
77

88
Метод **`concat()`** возвращает новый массив, состоящий из массива, на котором он был вызван, соединённого с другими массивами и/или значениями, переданными в качестве аргументов.
99

10-
{{EmbedInteractiveExample("pages/js/array-concat.html")}}
10+
{{InteractiveExample("JavaScript Demo: Array.concat()")}}
11+
12+
```js interactive-example
13+
const array1 = ["a", "b", "c"];
14+
const array2 = ["d", "e", "f"];
15+
const array3 = array1.concat(array2);
16+
17+
console.log(array3);
18+
// Expected output: Array ["a", "b", "c", "d", "e", "f"]
19+
```
1120

1221
## Синтаксис
1322

files/ru/web/javascript/reference/global_objects/array/fill/index.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,22 @@ slug: Web/JavaScript/Reference/Global_Objects/Array/fill
77

88
Метод **`fill()`** заполняет все элементы массива от начального до конечного индексов одним значением.
99

10-
{{EmbedInteractiveExample("pages/js/array-fill.html")}}
10+
{{InteractiveExample("JavaScript Demo: Array.fill()")}}
11+
12+
```js interactive-example
13+
const array1 = [1, 2, 3, 4];
14+
15+
// Fill with 0 from position 2 until position 4
16+
console.log(array1.fill(0, 2, 4));
17+
// Expected output: Array [1, 2, 0, 0]
18+
19+
// Fill with 5 from position 1
20+
console.log(array1.fill(5, 1));
21+
// Expected output: Array [1, 5, 5, 5]
22+
23+
console.log(array1.fill(6));
24+
// Expected output: Array [6, 6, 6, 6]
25+
```
1126

1227
## Синтаксис
1328

files/ru/web/javascript/reference/global_objects/array/filter/index.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@ slug: Web/JavaScript/Reference/Global_Objects/Array/filter
77

88
Метод **`filter()`** **создаёт новый массив со всеми элементами**, прошедшими проверку, задаваемую в передаваемой функции.
99

10-
{{EmbedInteractiveExample("pages/js/array-filter.html")}}
10+
{{InteractiveExample("JavaScript Demo: Array.filter()")}}
11+
12+
```js interactive-example
13+
const words = ["spray", "elite", "exuberant", "destruction", "present"];
14+
15+
const result = words.filter((word) => word.length > 6);
16+
17+
console.log(result);
18+
// Expected output: Array ["exuberant", "destruction", "present"]
19+
```
1120

1221
## Синтаксис
1322

files/ru/web/javascript/reference/global_objects/array/foreach/index.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,17 @@ slug: Web/JavaScript/Reference/Global_Objects/Array/forEach
77

88
Метод **`forEach()`** выполняет указанную функцию один раз для каждого элемента в массиве.
99

10-
{{EmbedInteractiveExample("pages/js/array-foreach.html")}}
10+
{{InteractiveExample("JavaScript Demo: Array.forEach()")}}
11+
12+
```js interactive-example
13+
const array1 = ["a", "b", "c"];
14+
15+
array1.forEach((element) => console.log(element));
16+
17+
// Expected output: "a"
18+
// Expected output: "b"
19+
// Expected output: "c"
20+
```
1121

1222
## Синтаксис
1323

files/ru/web/javascript/reference/global_objects/array/from/index.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ slug: Web/JavaScript/Reference/Global_Objects/Array/from
77

88
Метод **`Array.from()`** создаёт новый экземпляр `Array` из массивоподобного или итерируемого объекта.
99

10-
{{EmbedInteractiveExample("pages/js/array-from.html")}}
10+
{{InteractiveExample("JavaScript Demo: Array.from()")}}
11+
12+
```js interactive-example
13+
console.log(Array.from("foo"));
14+
// Expected output: Array ["f", "o", "o"]
15+
16+
console.log(Array.from([1, 2, 3], (x) => x + x));
17+
// Expected output: Array [2, 4, 6]
18+
```
1119

1220
## Синтаксис
1321

files/ru/web/javascript/reference/global_objects/array/includes/index.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,22 @@ l10n:
99

1010
Метод **`includes()`** экземпляров {{jsxref("Array")}} определяет, содержит ли массив определенное значение, возвращая `true` или `false`.
1111

12-
{{EmbedInteractiveExample("pages/js/array-includes.html")}}
12+
{{InteractiveExample("JavaScript Demo: Array.includes()")}}
13+
14+
```js interactive-example
15+
const array1 = [1, 2, 3];
16+
17+
console.log(array1.includes(2));
18+
// Expected output: true
19+
20+
const pets = ["cat", "dog", "bat"];
21+
22+
console.log(pets.includes("cat"));
23+
// Expected output: true
24+
25+
console.log(pets.includes("at"));
26+
// Expected output: false
27+
```
1328

1429
## Синтаксис
1530

files/ru/web/javascript/reference/global_objects/array/join/index.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,20 @@ slug: Web/JavaScript/Reference/Global_Objects/Array/join
99

1010
Метод **`join()`** объединяет все элементы массива (или [массивоподобного объекта](/ru/docs/Web/JavaScript/Guide/Indexed_collections#working_with_array-like_objects)) в строку.
1111

12-
{{EmbedInteractiveExample("pages/js/array-join.html")}}
12+
{{InteractiveExample("JavaScript Demo: Array.join()")}}
13+
14+
```js interactive-example
15+
const elements = ["Fire", "Air", "Water"];
16+
17+
console.log(elements.join());
18+
// Expected output: "Fire,Air,Water"
19+
20+
console.log(elements.join(""));
21+
// Expected output: "FireAirWater"
22+
23+
console.log(elements.join("-"));
24+
// Expected output: "Fire-Air-Water"
25+
```
1326

1427
## Синтаксис
1528

files/ru/web/javascript/reference/global_objects/array/keys/index.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,20 @@ slug: Web/JavaScript/Reference/Global_Objects/Array/keys
77

88
Метод **`keys()`** возвращает новый **итератор массива** **`Array Iterator`**, содержащий ключи каждого индекса в массиве.
99

10-
{{EmbedInteractiveExample("pages/js/array-keys.html")}}
10+
{{InteractiveExample("JavaScript Demo: Array.keys()")}}
11+
12+
```js interactive-example
13+
const array1 = ["a", "b", "c"];
14+
const iterator = array1.keys();
15+
16+
for (const key of iterator) {
17+
console.log(key);
18+
}
19+
20+
// Expected output: 0
21+
// Expected output: 1
22+
// Expected output: 2
23+
```
1124

1225
## Синтаксис
1326

files/ru/web/javascript/reference/global_objects/array/lastindexof/index.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,17 @@ slug: Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf
77

88
Метод **`lastIndexOf()`** возвращает последний индекс, по которому данный элемент может быть найден в массиве или -1, если такого индекса нет. Массив просматривается от конца к началу, начиная с индекса `fromIndex`.
99

10-
{{EmbedInteractiveExample("pages/js/array-lastindexof.html")}}
10+
{{InteractiveExample("JavaScript Demo: Array.lastIndexOf()")}}
11+
12+
```js interactive-example
13+
const animals = ["Dodo", "Tiger", "Penguin", "Dodo"];
14+
15+
console.log(animals.lastIndexOf("Dodo"));
16+
// Expected output: 3
17+
18+
console.log(animals.lastIndexOf("Tiger"));
19+
// Expected output: 1
20+
```
1121

1222
## Синтаксис
1323

files/ru/web/javascript/reference/global_objects/array/reduce/index.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,21 @@ slug: Web/JavaScript/Reference/Global_Objects/Array/reduce
77

88
Метод **`reduce()`** применяет функцию **reducer** к каждому элементу массива (слева-направо), возвращая одно результирующее значение.
99

10-
{{EmbedInteractiveExample("pages/js/array-reduce.html")}}
10+
{{InteractiveExample("JavaScript Demo: Array.reduce()")}}
11+
12+
```js interactive-example
13+
const array1 = [1, 2, 3, 4];
14+
15+
// 0 + 1 + 2 + 3 + 4
16+
const initialValue = 0;
17+
const sumWithInitial = array1.reduce(
18+
(accumulator, currentValue) => accumulator + currentValue,
19+
initialValue,
20+
);
21+
22+
console.log(sumWithInitial);
23+
// Expected output: 10
24+
```
1125

1226
## Синтаксис
1327

files/ru/web/javascript/reference/global_objects/array/reverse/index.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,21 @@ slug: Web/JavaScript/Reference/Global_Objects/Array/reverse
77

88
Метод **`reverse()`** на месте обращает порядок следования элементов массива. Первый элемент массива становится последним, а последний — первым.
99

10-
{{EmbedInteractiveExample("pages/js/array-reverse.html")}}
10+
{{InteractiveExample("JavaScript Demo: Array.reverse()")}}
11+
12+
```js interactive-example
13+
const array1 = ["one", "two", "three"];
14+
console.log("array1:", array1);
15+
// Expected output: "array1:" Array ["one", "two", "three"]
16+
17+
const reversed = array1.reverse();
18+
console.log("reversed:", reversed);
19+
// Expected output: "reversed:" Array ["three", "two", "one"]
20+
21+
// Careful: reverse is destructive -- it changes the original array.
22+
console.log("array1:", array1);
23+
// Expected output: "array1:" Array ["three", "two", "one"]
24+
```
1125

1226
## Синтаксис
1327

files/ru/web/javascript/reference/global_objects/array/slice/index.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,29 @@ slug: Web/JavaScript/Reference/Global_Objects/Array/slice
77

88
Метод **`slice()`** возвращает новый массив, содержащий копию части исходного массива.
99

10-
{{EmbedInteractiveExample("pages/js/array-slice.html")}}
10+
{{InteractiveExample("JavaScript Demo: Array.slice()")}}
11+
12+
```js interactive-example
13+
const animals = ["ant", "bison", "camel", "duck", "elephant"];
14+
15+
console.log(animals.slice(2));
16+
// Expected output: Array ["camel", "duck", "elephant"]
17+
18+
console.log(animals.slice(2, 4));
19+
// Expected output: Array ["camel", "duck"]
20+
21+
console.log(animals.slice(1, 5));
22+
// Expected output: Array ["bison", "camel", "duck", "elephant"]
23+
24+
console.log(animals.slice(-2));
25+
// Expected output: Array ["duck", "elephant"]
26+
27+
console.log(animals.slice(2, -1));
28+
// Expected output: Array ["camel", "duck"]
29+
30+
console.log(animals.slice());
31+
// Expected output: Array ["ant", "bison", "camel", "duck", "elephant"]
32+
```
1133

1234
## Синтаксис
1335

0 commit comments

Comments
 (0)